import _ from "lodash";
import {handleCopy, userType} from "../../utils";
import {Button, Image} from "antd";
import {Tooltips} from "../common";

interface Props {
    width?: number;
    onClick?: (e?: any) => any;
}
interface IdProps {
    pageNum?: any;
    pageSize?: any;
}

export const columnsIndex = {
    title: "序号",
    dataIndex: "index",
    key: "index",
    width: 50,
    render: (_: any, __: any, idx: any) => idx + 1,
};

export const getColumnsId = ({pageNum, pageSize}: IdProps) => ({
    ...columnsIndex,
    title: "",
    render: (_, __, idx: any) => idx + 1 + (pageNum - 1) * pageSize,
});

export const columnsRelevanceId = {
    title: "物料Id",
    dataIndex: "rid",
    key: "rid",
};
export const columnsOpenid = {
    title: "openId",
    dataIndex: "openId",
    key: "openId",
    render: title => <Tooltips title={title} />,
};
export const columnsHeaderImg = {
    width: 100,
    title: "头像",
    dataIndex: "headImgUrl",
    key: "headImgUrl",
    render: (src: string) => <Image width={50} src={src} />,
};

export const getColumnsName = ({width = 100, onClick}: Props = {}) => ({
    title: "用户名",
    dataIndex: "nickName",
    key: "nickName",
    width,
    render: (val, row) => (
        <Button size="small" type="link" danger onClick={() => (onClick ? onClick(row) : handleCopy(val))}>
            {val}
        </Button>
    ),
});

export const columnsApplyStatus = {
    title: "申请状态",
    dataIndex: "applyStatus",
    key: "applyStatus",
    render: val => (
        <Button size="small" type="text" danger>
            {val === "0" ? "申请中" : "已同意申请"}
        </Button>
    ),
};

export const columnsCreateTime = {
    title: "创建时间",
    dataIndex: "createDate",
    key: "createDate",
    width: 190,
};
export const columnsIdentity = {
    title: "用户类型",
    dataIndex: "identity",
    key: "identity",
    render: (id: string) => _.find(userType, {id})?.value,
};
export const columnsBindTime = {
    title: "绑定时间",
    dataIndex: "bindingTime",
    key: "bindingTime",
    width: 190,
};

export const columnsUpdateTime = {
    title: "更新时间",
    dataIndex: "updateDate",
    key: "updateDate",
    width: 170,
};

export const columnsMobile = {
    title: "手机号",
    dataIndex: "mobile",
    key: "mobile",
};
export const columnsCommissionRate = {
    title: "佣金比例",
    dataIndex: "commissionRate",
    key: "commissionRate",
};

export const columnsPositionId = {
    title: "推广位",
    dataIndex: "positionId",
    key: "positionId",
    render: txt => <Tooltips title={txt} />,
};
export const columnsPositionSubId = {
    title: "推广位三段ID",
    dataIndex: "positionSubId",
    key: "positionSubId",
};
export const columnsIsBind = {
    title: "用户绑定",
    dataIndex: "openId",
    key: "openId",
    render: txt => (
        <Button type="text" danger size="small">
            {txt ? "已绑定" : "未绑定"}
        </Button>
    ),
};

export const columnsDetail = {
    title: "查看详情",
};

export const columnsTitle = {
    title: "标题",
    dataIndex: "title",
    key: "title",
};
export const columnsSetting = {
    title: "操作",
    dataIndex: "setting",
    key: "setting",
    width: 150,
};
export const columnsCode = {
    title: "邀请码",
    dataIndex: "code",
    key: "code",
};

export const columnsPkId = {
    title: "pkId",
    dataIndex: "pkId",
    key: "pkId",
    width: 150,
};

export const PLATFORM: any = {
    weapp: "微信",
    qq: "QQ",
    tt: "抖音",
};

export const PLATFORMLIST: any = [
    {
        label: "微信",
        value: "weapp",
    },
    {
        label: "QQ",
        value: "qq",
    },
    {
        label: "抖音",
        value: "tt",
    },
];
export const columnImgRender = val => <Image src={`http:${val}`} width={50} />;

export const columnImage = {
    title: "图片",
    dataIndex: "productImage",
    render: columnImgRender,
};

export const priceInfo = [
    {title: "累计佣金", dataIndex: "totalCommission", key: "totalCommission"},
    {title: "累计佣金预估", dataIndex: "totalEsCommission", key: "totalEsCommission"},
    {title: "可用佣金", dataIndex: "availableCommission", key: "availableCommission"},
    {title: "已提现佣金", dataIndex: "usedCommission", key: "usedCommission"},
];
